package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.ClientUser;
import com.ruoyi.system.domain.TmcEmergencyAttach;
import com.ruoyi.system.domain.TmcPropertyMaintenance;
import com.ruoyi.system.mapper.TmcPropertyMaintenanceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TmcEmergencyMapper;
import com.ruoyi.system.domain.TmcEmergency;
import com.ruoyi.system.service.ITmcEmergencyService;

/**
 * 问题回收
 * Service业务层处理
 *
 * @author ruoyi
 * @date 2021-03-31
 */
@Service
public class TmcEmergencyServiceImpl implements ITmcEmergencyService {
    @Autowired
    private TmcEmergencyMapper tmcEmergencyMapper;

    @Override
    public List<TmcEmergency> selectTmcEmergencyList(TmcEmergency tmcEmergency) {
        List<TmcEmergency> tmcEmergencies = tmcEmergencyMapper.selectTmcEmergencyList(tmcEmergency);
        for (int i = 0; i <tmcEmergencies.size(); i++) {
            if (null!=tmcEmergencies.get(i).getClientId()){
                tmcEmergencies.get(i).setClientName(tmcEmergencyMapper.queryclientById(tmcEmergencies.get(i).getClientId()));
            }
            if (0!=tmcEmergencies.get(i).getPublicuserId()){
                tmcEmergencies.get(i).setUserName(tmcEmergencyMapper.queryUserById(tmcEmergencies.get(i).getPublicuserId()));
            }
        }
        return  tmcEmergencies ;
    }

    @Override
    public String attach(Long id) {

        return tmcEmergencyMapper.selectAttach(id);
    }

    @Override
    public int insertTmcEmergency(TmcEmergency tmcEmergency) {

        return tmcEmergencyMapper.insertTmcEmergency(tmcEmergency);
    }

    @Override
    public int updateclientById(TmcEmergency tmcEmergency) {
        return tmcEmergencyMapper.updateclientById(tmcEmergency);
    }

    @Override
    public int insertTmcEmergencyAttach(TmcEmergencyAttach tmcEmergencyAttach) {
        return tmcEmergencyMapper.insertTmcEmergencyAttach(tmcEmergencyAttach);
    }

    @Override
    public List<TmcEmergency> selectTmcEmergencyByUId(TmcEmergency tmcEmergency) {
        List<TmcEmergency> tmcEmergencyList = tmcEmergencyMapper.selectTmcEmergencyList(tmcEmergency);
        for (int i = 0; i < tmcEmergencyList.size(); i++) {
            //附件列表
            tmcEmergencyList.get(i).setAttachList(tmcEmergencyMapper.selectTmcEmergencyAttachById(tmcEmergencyList.get(i).getId()));
            //维修员工
            tmcEmergencyList.get(i).setClientName(tmcEmergencyMapper.queryclientById(tmcEmergencyList.get(i).getClientId()));
        }
        return tmcEmergencyList;
    }

    @Override
    public TmcEmergency selectTmcEmergencyById(Long id) {
        TmcEmergency tmcEmergency = tmcEmergencyMapper.selectTmcEmergencyById(id);
        List<TmcEmergencyAttach> tmcEmergencyAttaches = tmcEmergencyMapper.selectTmcEmergencyAttachById(id);
        tmcEmergency.setAttachList(tmcEmergencyAttaches);
        //维修员工
        tmcEmergency.setClientName(tmcEmergencyMapper.queryclientById(tmcEmergency.getClientId()));
        return tmcEmergency;
    }

}